﻿using AutoMapper;
using System;
using System.Reflection;
using Yto.AutoMapper.Attributes;

namespace Yto.AutoMapper.Extensions
{
    internal static class AutoMapperExtensions
    {
        //public static T MapTo<T>(this object obj)
        //{
        //    return Mapper.Map<T>(obj);
        //}

        //public static TD MapTo<TS,TD>(this TS source, TD destination)
        //{
        //    return Mapper.Map(source, destination);
        //}

        public static void CreateAutoAttributeMaps(
            this IMapperConfigurationExpression mapperConfigurationExpression, Type type)
        {
            foreach(var item in type.GetTypeInfo().GetCustomAttributes<BaseMapAttribute>())
            {
                item.CreateMap(mapperConfigurationExpression, type);
            }
        }
    }
}
